/**
 * Created by 林 on 2017/5/17 0017.
 */
var  panelCollapse1 = $('[data-panel="Collapse"]');
var  panelCollapse2 = $('[data-panel="Collapse"] .panel');
var  panelCollapse3 = $('[data-panel="Collapse"] .panel .list-group li');
for(var i=0;i<panelCollapse2.length;i++){
    panelCollapse2[i].index = true;
}
panelCollapse2.find('.panel-heading').click(function () {
    if( $(this).parent().get(0).index ){
        if( $(this).parent().hasClass('last-panel') ){
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideDown(300)
                .parent().find('.panel-heading')
                .css({'border-bottom-left-radius':0,'border-bottom-right-radius':0});
            $(this).parent().get(0).index = false;
        }else{
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideDown(300);
            $(this).parent().get(0).index = false;
        }
    }else{
        if( $(this).parent().hasClass('last-panel') ){
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideUp(300)
                .parent().css({'overflow':'hidden'});
            $(this).parent().get(0).index = true;
        }else{
            $(this).parent().find('.list-group,.table-responsive,.table,.panel-body').slideUp(300);
            $(this).parent().get(0).index = true;
        }

    }

});
var scroll = $(window).scrollTop();
function pub(num1, num2) {
    panelCollapse1.css({'position':'fixed','top':0,'width':panelCollapse1.parent().width() + 'px'});
    panelCollapse2.find('.list-group,.table-responsive,.table,.panel-body').css('display','none');
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','block');
    panelCollapse2.filter(':nth-child('+ num1 +')').get(0).index = false;

    panelCollapse3.css({'background':'#fff', 'color':'#555'});
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group li:nth-child('+ num2 +')').css({'background':'#5fb4c4', 'color':'#fff'});
}

if( scroll >= 350 && scroll < 765 ){
    pub(1, 1);
}else if( scroll >= 765 && scroll < 1280 ) {
    pub(1, 2);
}else if( scroll >= 1280 && scroll < 1630 ) {
    pub(1, 3);
}else if( scroll >= 1630 && scroll < 2595 ) {
    pub(1, 4);
}else if( scroll >= 2595 && scroll < 3865 ) {
    pub(2, 1);
}else if( scroll >= 3865 && scroll < 6546 ) {
    pub(2, 2);
}else if( scroll >= 6546 && scroll < 6870 ) {
    pub(2, 3);
}else if( scroll >= 6870 && scroll < 7220 ) {
    pub(2, 4);
}else if( scroll >= 7220 && scroll < 7705 ) {
    pub(3, 1);
}else if( scroll >= 7705 && scroll < 8270 ) {
    pub(3, 2);
}else if( scroll >= 8270 && scroll < 8735 ) {
    pub(3, 3);
}else if( scroll >= 8735 && scroll < 9175 ) {
    pub(3, 4);
}else if( scroll >= 9175 && scroll < 9574 ) {
    pub(3, 5);
}else if( scroll >= 9574 && scroll < 10294 ) {
    pub(3, 6);
}else if( scroll >= 10294 && scroll < 11000 ) {
    pub(3, 7);
}else if( scroll >= 11000 && scroll <= 11919 ) {
    pub(4, 1);
}else if( scroll >= 11919 && scroll <= 12640 ) {
    pub(4, 2);
}else if( scroll >= 12640 && scroll <= 13360 ) {
    pub(4, 3);
}else if( scroll >= 13360 && scroll <= 15560 ) {
    pub(4, 4);
}else if( scroll >= 15560 && scroll <= 16100 ) {
    pub(4, 5);
}else if( scroll >= 16100 && scroll <= 16385 ) {
    pub(4, 6);
}else if( scroll >= 16385 && scroll <= 17130 ) {
    pub(5, 1);
}else if( scroll >= 17130 && scroll <= 17729 ) {
    pub(5, 2);
}else if( scroll >= 17729 && scroll <= 18769 ) {
    pub(5, 3);
}else if( scroll >= 18769 && scroll <= 19049 ) {
    pub(5, 4);
}else if( scroll >= 19049 && scroll <= 19609 ) {
    pub(6, 1);
}else if( scroll >= 19609 && scroll <= 19976 ) {
    pub(6, 2);
}else if( scroll >= 19976 && scroll <= 21740 ) {
    pub(7, 1);
}else if( scroll >= 21740 && scroll <= 22005 ) {
    pub(7, 2);
}else if( scroll >= 22005 && scroll <= 22430 ) {
    pub(7, 3);
}else if( scroll >= 22430 ) {
    pub(7, 4);
}else{
    panelCollapse1.removeAttr("style");
    panelCollapse3.css({'background':'#fff', 'color':'#555'});
}
function pubScroll(num1,num2,num3) {
    panelCollapse1.css({'position':'fixed','top':0,'width':panelCollapse1.parent().width() + 'px'});

    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').slideUp(300,function () {
        panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','none');
        panelCollapse2.filter(':nth-child('+ num1 +')').get(0).index = true;
    });
    panelCollapse2.filter(':nth-child('+ num2 +')').find('.list-group,.table-responsive,.table,.panel-body').slideDown(300,function () {
        panelCollapse2.filter(':nth-child('+ num2 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','block');
        panelCollapse2.filter(':nth-child('+ num2 +')').get(0).index = false;

        panelCollapse3.css({'background':'#fff', 'color':'#555'});
        panelCollapse2.filter(':nth-child('+ num2 +')').find('.list-group li:nth-child('+ num3 +')').css({'background':'#5fb4c4', 'color':'#fff'});
    });
}
function pubChild(num1, num2) {
    panelCollapse1.css({'position':'fixed','top':0,'width':panelCollapse1.parent().width() + 'px'});
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','block');
    panelCollapse2.not(':nth-child('+ num1 +')').find('.list-group,.table-responsive,.table,.panel-body').css('display','none');

    panelCollapse3.css({'background':'#fff', 'color':'#555'});
    panelCollapse2.filter(':nth-child('+ num1 +')').find('.list-group li:nth-child('+ num2 +')').css({'background':'#5fb4c4', 'color':'#fff'});
}
$(window).scroll(function () {
    var scroll = $(window).scrollTop();
    if( scroll >= 350 && scroll < 765 ){
        pubScroll(2,1,1);
    }else if( scroll >= 765 && scroll < 1280 ) {
        pubChild(1,2);
    }else if( scroll >= 1280 && scroll < 1630 ) {
        pubChild(1,3);
    }else if( scroll >= 1630 && scroll < 2595 ) {
        pubScroll(2,1,4);
    }else if( scroll >= 2595 && scroll < 3865 ) {
        pubScroll(1,2,1);
    }else if( scroll >= 3865 && scroll < 6546 ) {
        pubChild(2,2);
    }else if( scroll >= 6546 && scroll < 6870 ) {
        pubChild(2,3);
    }else if( scroll >= 6870 && scroll < 7220 ) {
        pubScroll(3,2,4);
    }else if( scroll >= 7220 && scroll < 7705 ) {
        pubScroll(2,3,1);
    }else if( scroll >= 7705 && scroll < 8270 ) {
        pubChild(3,2);
    }else if( scroll >= 8270 && scroll < 8735 ) {
        pubChild(3,3);
    }else if( scroll >= 8735 && scroll < 9175 ) {
        pubChild(3,4);
    }else if( scroll >= 9175 && scroll < 9574 ) {
        pubChild(3,5);
    }else if( scroll >= 9574 && scroll < 10294 ) {
        pubChild(3,6);
    }else if( scroll >= 10294 && scroll < 11000 ) {
        pubScroll(4,3,7);
    }else if( scroll >= 11000 && scroll <= 11919 ) {
        pubScroll(3,4,1);
    }else if( scroll >= 11919 && scroll <= 12640 ) {
        pubChild(4,2);
    }else if( scroll >= 12640 && scroll <= 13360 ) {
        pubChild(4,3);
    }else if( scroll >= 13360 && scroll <= 15560 ) {
        pubChild(4,4);
    }else if( scroll >= 15560 && scroll <= 16100 ) {
        pubChild(4,5);
    }else if( scroll >= 16100 && scroll <= 16385 ) {
        pubScroll(5,4,6);
    }else if( scroll >= 16385 && scroll <= 17130 ) {
        pubScroll(4,5,1);
    }else if( scroll >= 17130 && scroll <= 17729 ) {
        pubChild(5,2);
    }else if( scroll >= 17729 && scroll <= 18769 ) {
        pubChild(5,3);
    }else if( scroll >= 18769 && scroll <= 19049 ) {
        pubScroll(6,5,4);
    }else if( scroll >= 19049 && scroll <= 19609 ) {
        pubScroll(5,6,1);
    }else if( scroll >= 19609 && scroll <= 19976 ) {
        pubScroll(7,6,2);
    }else if( scroll >= 19976 && scroll <= 21740 ) {
        pubScroll(6,7,1);
    }else if( scroll >= 21740 && scroll <= 22005 ) {
        pubChild(7,2);
    }else if( scroll >= 22005 && scroll <= 22430 ) {
        pubChild(7,3);
        panelCollapse1.css({'position':'fixed','top':'-150px','width':panelCollapse1.parent().width() + 'px'});
    }else if( scroll >= 22430 ) {
        pubChild(7,4);
        panelCollapse1.css({'position':'fixed','top':'-150px','width':panelCollapse1.parent().width() + 'px'});
    }else{
        panelCollapse1.removeAttr("style");
        panelCollapse2.filter(':nth-child(1)').find('.list-group,.table-responsive,.table,.panel-body').slideUp(300,function () {
            panelCollapse2.filter(':nth-child(1)').get(0).index = true;

            panelCollapse3.css({'background':'#fff', 'color':'#555'});
        });
    }

});